package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fulbitofacil.modelo.Persona;
import fulbitofacil.negocio.ComentarioNegocio;

/**
 * Servlet implementation class guardarComentariodeCancha
 */
@WebServlet("/guardarComentarioDeCancha")
public class guardarComentarioDeCanchaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public guardarComentarioDeCanchaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		int idCancha = Integer.parseInt(request.getParameter("idCancha"));
		int idComentarioPadre=0;
		String comentario = request.getParameter("coment");
		int calificacion = Integer.parseInt(request.getParameter("calific"));
		
		HttpSession session = request.getSession();
		Persona p = (Persona)session.getAttribute("Persona");
		
		
		int idPersona = p.getId_persona();
	
		
		ComentarioNegocio neg = new ComentarioNegocio();
		
		System.out.println(comentario);
		System.out.println(calificacion);
		System.out.println(idComentarioPadre);
		System.out.println(idCancha);
		System.out.println(idPersona);
		
		neg.comentarUnaCancha(comentario, calificacion, idComentarioPadre, idCancha, idPersona);
		
		
		String mensaje = "Usted agrego el comentario correctamente";
		request.setAttribute("msg", mensaje);
		RequestDispatcher rd = request.getRequestDispatcher("MostrarUnaCancha.jsp?idCancha="+idCancha);
		rd.forward(request, response);
		
		
	}

}
